package com.zsg.controller;

import com.zsg.pojo.Role;
import com.zsg.pojo.User;
import com.zsg.pojo.UserRole;
import com.zsg.service.RoleService;
import com.zsg.utils.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Gadmin
 */
@Api("角色操作接口")
@RestController
@RequestMapping("/role")
public class RoleController {
    @Autowired
    private RoleService roleService;
//    @Autowired
//    private ResponseData responseData;

    @PostMapping("/addRole")
    @ApiOperation("添加角色")
    public ResponseData addRole(@RequestBody Role role){
        ResponseData responseData = roleService.addRole(role);
        return responseData;
    }

    @PostMapping("/delRole")
    @ApiOperation("删除角色")
    public ResponseData delRole(@RequestBody Role role){
        ResponseData responseData = roleService.delRole(role);
        return responseData;
    }


    @PostMapping("/updateRole")
    @ApiOperation("修改角色")
    public ResponseData updateRole(@RequestBody Role role){
        ResponseData responseData = roleService.updateRole(role);
        return responseData;
    }

    @PostMapping("/queryRole")
    @ApiOperation("查询角色，根据roleName查询")
    public ResponseData queryRole(@RequestBody Role role){
        ResponseData responseData = roleService.queryRole(role);
        return responseData;
    }


    @PostMapping("/userBoundRole")
    @ApiOperation("为用户绑定角色")
    public ResponseData userBoundRole(int userId,@RequestBody List<Integer> roleId){
        ResponseData responseData = roleService.userBoundRole(userId,roleId);
        return responseData;
    }

    @PostMapping("/queryUserRole")
    @ApiOperation("查询用户绑定的角色")
    public ResponseData queryUserRole(@RequestBody User user){
        ResponseData responseData = roleService.queryUserRole(user);
        return responseData;
    }

    @PostMapping("/delUserRole")
    @ApiOperation("取消绑定,userId")
    public ResponseData delUserRole(@RequestBody UserRole userRole){
        ResponseData responseData = roleService.delUserRole(userRole);
        return responseData;
    }



}
